/**
 * Created by IntelliJ IDEA.
 * User: Taras_Brzezinsky
 * Date: 8/29/11
 * Time: 6:02 PM
 * To change this template use File | Settings | File Templates.
 */

import java.util.*;
import java.io.*;
import java.math.BigInteger;

public class TaskL extends Thread {
    public TaskL() {
        try {
            this.input = new BufferedReader(new FileReader("input.txt"));
            this.output = new PrintWriter("output.txt");
            this.setPriority(Thread.MAX_PRIORITY);
        } catch (Throwable e) {

        }
    }

    static class Edge implements Comparable<Edge> {
        int to;
        long cost;

        public Edge(int to, long cost) {
            this.to = to;
            this.cost = cost;
        }

        public int compareTo(Edge o) {
            return (int) Math.signum(this.cost - o.cost);
        }
    }

    static void dijkstra(int s) {

        Arrays.fill(d, INF);
        d[s] = 0;
        PriorityQueue<Edge> q = new PriorityQueue<Edge>();
        q.add(new Edge(s, 0));
        while (!q.isEmpty()) {
            Edge current = q.poll();
            if (current.cost > d[current.to]) {
                continue;
            }
            for (int i = 0 ; i < g.length; ++i) {
                if (g[current.to][i] == INF) {
                    continue;
                }
                if (d[current.to] + g[current.to][i] < d[i]) {
                    d[i] = d[current.to] + g[current.to][i];
                    q.add(new Edge(i, d[i]));
                }
            }
        }
    }


    private void solve() throws Throwable {
        int n = nextInt();
        g = new long[n + 1][n + 1];
        d = new long[n + 1];
        for (long[] current : g) {
            Arrays.fill(current, INF);
        }
        int m = nextInt();
        for (int curEdge = 0; curEdge < m; ++curEdge) {
            int a = nextInt(), b = nextInt();
            long c = nextLong();
            if (a == b) {
                continue;
            }
            g[a][b] = Math.min(g[a][b], c);
            g[b][a] = g[a][b];
        }
        int K = nextInt();
        for (int i = 0; i < K; ++i) {
            int where = nextInt();
            long C = nextLong();
            g[0][where] = Math.min(g[0][where], C);
            g[where][0] = g[0][where];
        }
        int destination = nextInt();
        dijkstra(0);
        output.println(d[destination]);
    }

    public void run() {
        try {
            solve();
        } catch (Throwable e) {
            System.err.println(e.getMessage());
            e.printStackTrace();
            System.exit(666);
        } finally {
            output.flush();
            output.close();
        }
    }

    public static void main(String[] args) {
        new TaskL().start();
    }

    private int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    private long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    private double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    private String nextToken() throws IOException {
        while (tokens == null || !tokens.hasMoreTokens()) {
            tokens = new StringTokenizer(input.readLine());
        }
        return tokens.nextToken();
    }
    static  long INF = Long.MAX_VALUE / 3;
    static long[] d;
    static long [][]g;
    private BufferedReader input;
    private PrintWriter output;
    private StringTokenizer tokens = null;
}
